<!-- 工艺信息 -->
<template>
  <div>
    <div class="title pl0">
      <h3>工艺信息</h3>
      <el-button
        type="text"
        v-if="isDisable && isLocked == '待锁定'"
        @click="handleEdit"
        >编辑</el-button
      >
    </div>
    <el-table :data="formData.productTechniqueList" border style="width: 100%">
      <el-table-column type="index" label="序号" width="50" />
      <el-table-column
        prop="craftCode"
        width="150"
        align="center"
        label="工艺编号"
      >
        <template slot-scope="scope">
          {{ !scope.row.craftCode ? "选择后显示" : scope.row.craftCode }}
        </template>
      </el-table-column>
      <el-table-column
        prop="school"
        width="150"
        align="center"
        label="工艺名称"
      >
        <template slot-scope="scope">
          <el-select
            filterable
            v-model="scope.row.craftCode"
            v-if="!isDisable"
            placeholder="请选择工艺"
            @change="handleCraftChange(scope.$index, $event)"
            size="small"
          >
            <el-option
              :label="item.name"
              :value="item.code"
              v-for="(item, index) in craftList"
              :key="index"
            />
          </el-select>
          <span v-else>
            {{
              querySelectName(craftList, scope.row.craftCode, "name", "code")
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="school"
        width="150"
        align="center"
        label="默认设备"
      >
        <template slot-scope="scope">
          <el-select
            filterable
            v-model="scope.row.deviceCode"
            v-if="!isDisable"
            placeholder="请选择设备"
            clearable
            size="mini"
          >
            <el-option
              v-for="item in scope.row.produceMachineList"
              :key="item.equipmentCode"
              :label="item.equipmentName"
              :value="item.equipmentCode"
            />
          </el-select>
          <span v-else>
            {{
              querySelectName(
                scope.row.produceMachineList,
                scope.row.deviceCode,
                "equipmentName",
                "equipmentCode"
              )
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="school" align="center" label="工艺要求">
        <template slot-scope="scope">
          <el-input
            v-if="!isDisable"
            v-model="scope.row.craftRequirement"
            placeholder="请输入内容"
            size="small"
          />
          <span v-else>{{ scope.row.craftRequirement }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="dataCardState"
        align="center"
        width="120px"
        label="工艺资料卡状态"
        v-if="isDisable"
      >
        <template slot-scope="scope">
          <template v-if="scope.row.productTechniqueCardState === 0">
            <el-tag type="info" size="small">未填写</el-tag>
          </template>
          <template v-else-if="scope.row.productTechniqueCardState === 1">
            <el-tag type="" size="small">已填写</el-tag>
          </template>
          <template v-else>
            <el-tag type="success" size="small">已锁定</el-tag>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        prop="dataCardOperate"
        align="center"
        width="120px"
        label="工艺操作"
        v-if="isDisable"
      >
        <template slot-scope="scope">
          <el-button type="text" @click="handleCarSee(scope.row)">
            <p>编辑</p>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="100px"
        fixed="right"
        align="center"
        v-if="!isDisable"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            v-if="formData.productTechniqueList.length - 1 != scope.$index"
            @click="handleCopyRow(scope.row, scope.$index)"
            >复制</el-button
          >
          <el-button
            type="text"
            v-if="formData.productTechniqueList.length - 1 != scope.$index"
            @click="handleDeleteRow(scope.row, scope.$index)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="footer mt16" v-if="!isDisable">
      <el-button size="small" @click="handleCancel">取消</el-button>
      <el-button size="small" class="ml16" type="primary" @click="handleSave"
        >保存</el-button
      >
    </div>
    <!-- 成品型号弹出层   -->
    <el-dialog
      title="技术资料卡"
      :visible.sync="pupState"
      :close-on-click-modal="false"
      custom-class="comDialog"
      width="80%"
    >
      <div class="dialogDody">
        <el-form
          ref="personnelForm"
          :model="cartFormData"
          label-width="80px"
          :disabled="disabled"
          class="dialogForm"
        >
          <div class="item">
            <div class="item-title">
              <h3>基础讯息</h3>
            </div>
            <div class="item-content list list_3">
              <el-form-item label="产品名称" prop="">
                <el-input
                  :value="form.productName"
                  placeholder="自动获取"
                  size="small"
                  disabled
                />
              </el-form-item>
              <el-form-item label="产品编码" prop="">
                <el-input
                  :value="form.productNumber"
                  placeholder="自动获取"
                  size="small"
                  disabled
                />
              </el-form-item>
              <el-form-item label="客户名称" prop="">
                <el-input
                  :value="form.customerName"
                  placeholder="自动获取"
                  size="small"
                  disabled
                />
              </el-form-item>
              <el-form-item label="工艺名称" prop="">
                <el-select
                  filterable
                  :value="rowData.craftCode"
                  disabled
                  placeholder="请选择工艺"
                  size="small"
                >
                  <el-option
                    :label="item.name"
                    :value="item.code"
                    v-for="(item, index) in craftList"
                    :key="index"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="版筒轮号" prop="">
                <el-input
                  v-model="cartFormData.baseData.sBanTongLunHao"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="印刷跳距" prop="">
                <el-input
                  v-model="cartFormData.baseData.sYinShuaTiaoJu"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="模切跳距" prop="">
                <el-input
                  v-model="cartFormData.baseData.sMoQieTiaoJu"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="虚刀" prop="">
                <el-input
                  v-model="cartFormData.baseData.sXuDao"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="复合" prop="">
                <el-input
                  v-model="cartFormData.baseData.sFuHe"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="杀胶" prop="">
                <el-input
                  v-model="cartFormData.baseData.sShaJiao"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="胶面印刷" prop="">
                <el-input
                  v-model="cartFormData.baseData.sJiaoMianYinShua"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="烫金" prop="">
                <el-select
                  v-model="cartFormData.baseData.sTangJin"
                  filterable
                  placeholder="请选择"
                  size="small"
                >
                  <el-option label="热烫" value="热烫" />
                  <el-option label="冷烫" value="冷烫" />
                </el-select>
              </el-form-item>
              <el-form-item label="覆膜" prop="">
                <el-input
                  v-model="cartFormData.baseData.sFuMo"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="光油" prop="">
                <el-input
                  v-model="cartFormData.baseData.sGuangYou"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="喷码" prop="">
                <el-input
                  v-model="cartFormData.baseData.sPenMa"
                  placeholder="请输入"
                  size="small"
                />
              </el-form-item>
            </div>
          </div>
          <div class="item">
            <div class="item-title">
              <h3>基础讯息</h3>
            </div>
            <div class="item-content">
              <el-table
                :data="cartFormData.machineData"
                border
                style="width: 100%"
              >
                <el-table-column type="index" label="序号" width="50" />
                <el-table-column prop="prop1" align="left" label="适用机台">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.machineCode"
                      placeholder="请选择"
                      size="small"
                      :disabled="disabled"
                      filterable
                      @change="
                        handleMachineChange(scope.row, scope.$index, $event)
                      "
                    >
                      <el-option
                        v-for="item in allMaterielClass"
                        :key="item.machineCode"
                        :label="item.machineName"
                        :value="item.machineCode"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column prop="prop2" align="left" label="预调机时间">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.pretreatmentTime"
                      :disabled="disabled"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop3" align="left" label="建议速度">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.recommendedSpeed"
                      :disabled="disabled"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop4" align="left" label="出卷张力">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.coilingTension"
                      :disabled="disabled"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop5" align="left" label="收卷张力">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.windingTension"
                      :disabled="disabled"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop6" align="left" label="覆卷张力">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.coilTension"
                      :disabled="disabled"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="100px"
                  fixed="right"
                  align="center"
                  v-if="!disabled"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      @click="handleCopy(scope.row, scope.$index, 1)"
                      v-if="cartFormData.machineData.length - 1 != scope.$index"
                    >
                      <p>复制</p>
                    </el-button>
                    <el-button
                      type="text"
                      @click="handleDelete(scope.row, scope.$index, 1)"
                      v-if="cartFormData.machineData.length - 1 != scope.$index"
                    >
                      <p>删除</p>
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
          <div class="item">
            <div class="item-title">
              <h3>材料信息</h3>
            </div>
            <div class="item-content">
              <el-table
                :data="cartFormData.materialData"
                border
                style="width: 100%"
              >
                <el-table-column type="index" label="序号" width="50" />
                <el-table-column
                  prop="specificationCode"
                  width="150"
                  align="center"
                  label="规格编号"
                >
                  <template slot-scope="scope">
                    {{ scope.row.specificationCode || "--" }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="goodsType"
                  width="100"
                  align="center"
                  label="物料类型"
                >
                  <template slot-scope="scope">
                    {{ scope.row.goodsType || "--" }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="school"
                  width="250"
                  align="center"
                  label="供应商"
                >
                  <template slot-scope="scope">
                    <el-select
                      filterable
                      v-model="scope.row.supplierCode"
                      placeholder="请选择供应商"
                      disabled
                      size="small"
                      @change="supplierChange(scope.row, $event)"
                    >
                      <el-option
                        :key="item.supplierID"
                        :label="item.supplierName"
                        :value="item.supplierCode"
                        v-for="(item, index) in allSupliers"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column prop="school" align="center" label="物料名称">
                  <template slot-scope="scope">
                    <el-select
                      filterable
                      v-model="scope.row.goodsCode"
                      placeholder="请选择物料"
                      disabled
                      @change="
                        handleMaterialNameChange(
                          scope.row,
                          scope.$index,
                          $event
                        )
                      "
                      size="small"
                    >
                      <el-option
                        :label="item.goodsName"
                        :value="item.goodsCode"
                        v-for="(item, index) in scope.row.materialList"
                        :key="index"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="specificationCode"
                  align="center"
                  label="规格型号"
                >
                  <template slot-scope="scope">
                    <el-select
                      filterable
                      v-model="scope.row.specificationCode"
                      placeholder="请选择规格型号"
                      disabled
                      size="small"
                    >
                      <el-option
                        :label="item.specificationName"
                        :value="item.specificationCode"
                        v-for="(item, index) in scope.row
                          .goodsSpecificationList"
                        :key="index"
                      />
                    </el-select>
                  </template>
                </el-table-column>
               
                <!-- <el-table-column
                  label="操作"
                  width="100px"
                  fixed="right"
                  align="center"
                  v-if="!disabled"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      @click="handleCopy(scope.row, scope.$index, 2)"
                      v-if="
                        cartFormData.materialData.length - 1 != scope.$index
                      "
                    >
                      <p>复制</p>
                    </el-button>
                    <el-button
                      type="text"
                      @click="handleDelete(scope.row, scope.$index, 2)"
                      v-if="
                        cartFormData.materialData.length - 1 != scope.$index
                      "
                    >
                      <p>删除</p>
                    </el-button>
                  </template>
                </el-table-column> -->
              </el-table>
            </div>
          </div>
          <div class="item">
            <div class="item-title">
              <h3>油墨配方</h3>
            </div>
            <div class="item-content">
              <el-table :data="cartFormData.inkData" border style="width: 100%">
                <el-table-column type="index" label="序号" width="50" />
                <el-table-column
                  prop="prop1"
                  align="left"
                  label="颜色名称"
                  width="120"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.colorName"
                      :disabled="disabled"
                      @blur="handleAddRow(scope.row, scope.$index)"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop2"
                  align="left"
                  label="油墨代号"
                  width="120"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.inkCodeName"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop4"
                  align="left"
                  label="油墨配比"
                  min-width="300"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.inkRatio"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop7"
                  align="left"
                  label="网纹辊线数"
                  width="120"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.aniloxRollsQuantity"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop8"
                  align="left"
                  label="目数"
                  width="120"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.meshQuantity"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop5" width="120" align="left" label="供应商">
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.supplier"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="100px"
                  fixed="right"
                  align="center"
                  v-if="!disabled"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      @click="handleCopy(scope.row, scope.$index, 3)"
                      v-if="cartFormData.inkData.length - 1 != scope.$index"
                    >
                      <p>复制</p>
                    </el-button>
                    <el-button
                      type="text"
                      @click="handleDelete(scope.row, scope.$index, 3)"
                      v-if="cartFormData.inkData.length - 1 != scope.$index"
                    >
                      <p>删除</p>
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
          <div class="item">
            <div class="item-title">
              <h3>客户品质要求</h3>
            </div>
            <div class="item-content">
              <el-checkbox
                v-model="cartFormData.baseData.scanBarcode"
                label="条码扫读"
              ></el-checkbox>
              <el-checkbox
                v-model="cartFormData.baseData.testInkability"
                label="着墨性测试"
              ></el-checkbox>
              <el-checkbox
                v-model="cartFormData.baseData.testAbrasion"
                label="耐磨测试"
              ></el-checkbox>
              <el-checkbox
                v-model="cartFormData.baseData.testTemperature"
                label="高低温测试"
              ></el-checkbox>
              <el-checkbox
                v-model="cartFormData.baseData.testAlcohol"
                label="耐酒精测试"
              ></el-checkbox>
              <el-checkbox
                v-model="cartFormData.baseData.testStickiness"
                label="粘性测试"
              ></el-checkbox>
              <el-checkbox
                v-model="cartFormData.baseData.other"
                label="其它"
              ></el-checkbox>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <div class="flex flex_between">
          <div></div>
          <div>
            <el-button size="mini" @click="pupState = false">
              <p>取 消</p>
            </el-button>
            <el-button size="mini" type="primary" @click="handleIsLocked">
              <p v-if="disabled">解锁</p>
              <p v-else>锁定</p>
            </el-button>
            <el-button
              element-loading-spinner="el-icon-loading"
              type="primary"
              size="mini"
              v-if="!disabled"
              @click="handleCarSave"
            >
              <p>保 存</p>
            </el-button>
          </div>
        </div>
      </span>
    </el-dialog>
  </div>
</template>

      <script>
import { querySelectName } from "@/utils";
export default {
  props: {
    productCode: {
      type: String,
      default: () => {
        return "";
      },
    },
    isLocked: {
      type: String,
      default: () => {
        return "";
      },
    },
    isShowEdits: {
      type: Boolean,
      default: () => {
        return false;
      },
    },
    formModel: {
      type: Object,
      default: () => {},
    },
  },

  watch: {
    formModel: {
      handler(newVal, oldVal) {
        this.form = newVal.baseData;
        this.formData.productTechniqueList = newVal.productTechniqueList;
        if (this.formData.productTechniqueList.length > 0) {
          this.formData.productTechniqueList.forEach((item) => {
            item.produceMachineList.forEach((x) => {
              x.equipmentName = x.machineName;
              x.equipmentCode = x.machineCode;
            });
          });
        }
        this.$forceUpdate();
      },
    },
  },
  data() {
    return {
      querySelectName,
      formData: {
        productCode: this.productCode,
        productTechniqueList: [],
      },
      disabled: true,
      form: {},
      isDisable: true,
      craftList: [], //工艺列表数据
      allMaterielClass: [], //机台
      allSupliers: [],
      // equipmentList: [], //设备列表
      options: [],
      rowData: {},
      pupState: false,
      cartFormData: {
        baseData: {
          productTechniqueCardID: 0,
          productTechniqueCardCode: "",
          productTechniqueCode: "",
          craftCode: "",
          deviceCode: "",
          productCode: "",
          sBanTongLunHao: "",
          sYinShuaTiaoJu: "",
          sMoQieTiaoJu: "",
          sXuDao: "",
          sFuHe: "",
          sJiaoMianYinShua: "",
          sTangJin: "",
          sFuMo: "",
          sGuangYou: "",
          sPenMa: "",
          scanBarcode: true,
          testInkability: true,
          testAbrasion: true,
          testTemperature: true,
          testAlcohol: true,
          testStickiness: true,
          other: true,
        },
        machineData: [
          {
            productTechniqueCardMachineID: 0,
            productTechniqueCardMachineCode: "",
            productTechniqueCardCode: "",
            machineCode: "",
            pretreatmentTime: "",
            recommendedSpeed: "",
            coilingTension: "",
            windingTension: "",
            coilTension: "",
          },
        ],
        materialData: [
          {
            productTechniqueCardMaterialID: 0,
            productTechniqueCardMaterialCode: "",
            productTechniqueCardCode: "",
            goodsCode: "",
            specificationCode: "",
            supplierCode: "",
            thickness: "",
          },
        ],
        inkData: [
          {
            productTechniqueCardInkID: 0,
            productTechniqueCardInkCode: "",
            productTechniqueCardCode: "",
            colorName: "",
            inkCodeName: "",
            inkRatio: "",
            aniloxRollsQuantity: "",
            meshQuantity: "",
            supplier: "",
          },
        ],
      },
    };
  },
  created() {
    this.getCraftList();
  },
  methods: {
    //表格选择事件
    handlePriceChange(row, index, event) {
      if (index == this.formData.productTechniqueList.length - 1) {
        this.formData.productTechniqueList.push({
          productTechniqueID: 0,
          productTechniqueCode: "",
          craftCode: "",
          deviceCode: "",
          craftRequirement: "",
          productCode: this.productCode,
        });
      }
    },

    // 获取供应商
    getSupplier() {
      this.$api.mater.GetAllSuppliers().then((res) => {
        this.allSupliers = res;
      });
    },

    //锁定/解锁
    handleIsLocked() {
      let obj = {
        productTechniqueCardCode: this.cartFormData.baseData.productTechniqueCardCode,
        isLocked: this.disabled?0:1,
      };
      this.$api.business.UpdateProductTechniqueCardIsLocked(obj).then(() => {
        this.$message.success("保存成功");
        this.getDetail();
        this.pupState = false;
      });
    },

    //复制
    handleCopy(row, index, type) {
      if (type == 1) {
        this.cartFormData.machineData.splice(
          index,
          0,
          JSON.parse(JSON.stringify(row))
        );
      } else if (type == 2) {
        this.cartFormData.materialData.splice(
          index,
          0,
          JSON.parse(JSON.stringify(row))
        );
      } else if (type == 3) {
        this.cartFormData.inkData.splice(
          index,
          0,
          JSON.parse(JSON.stringify(row))
        );
      }
    },

    //删除
    handleDelete(row, index, type) {
      if (type == 1) {
        this.cartFormData.machineData.splice(index, 1);
      } else if (type == 2) {
        this.cartFormData.materialData.splice(index, 1);
      } else if (type == 3) {
        this.cartFormData.inkData.splice(index, 1);
      }
    },

    //机台选择事件
    handleMachineChange(row, index, e) {
      if (index == this.cartFormData.machineData.length - 1) {
        this.cartFormData.machineData.push({
          productTechniqueCardMachineID: 0,
          productTechniqueCardMachineCode: "",
          productTechniqueCardCode: "",
          machineCode: "",
          pretreatmentTime: "",
          recommendedSpeed: "",
          coilingTension: "",
          windingTension: "",
          coilTension: "",
        });
      }
    },

    handleAddRow(row, index) {
      if (index == this.cartFormData.inkData.length - 1) {
        this.cartFormData.inkData.push({
          productTechniqueCardInkID: 0,
          productTechniqueCardInkCode: "",
          productTechniqueCardCode: "",
          colorName: "",
          inkCodeName: "",
          inkRatio: "",
          aniloxRollsQuantity: "",
          meshQuantity: "",
          supplier: "",
        });
      }
    },

    // 获取所有设备
    getMaterielClass() {
      this.$api.product
        .GetMatchProductDevices({
          likeWords: "",
          machineState: 1,
        })
        .then((res) => {
          this.allMaterielClass = res;
        });
    },

    //删除
    handleDeleteRow(row, index) {
      this.formData.productTechniqueList.splice(index, 1);
    },

    //复制
    handleCopyRow(row, index) {
      this.formData.productTechniqueList.splice(
        index,
        0,
        JSON.parse(JSON.stringify(row))
      );
    },

    //查看
    handleCarSee(row) {
      this.rowData = row;
      this.getMaterielClass();
      this.getSupplier();
      this.cartFormData.baseData.productTechniqueCode =
        row.productTechniqueCode;
      this.$api.business
        .GetProductTechniqueCardDetails({
          productTechniqueCode: row.productTechniqueCode,
        })
        .then((res) => {
          this.cartFormData = res;
          if(this.cartFormData.materialData.length>0){
            this.cartFormData.materialData.forEach((item) => {
              this.$api.mater
                .GetGoodsSpecificationBySupplierCode({
                  queryBy: 0,
                  queryValue: item.supplierCode,
                })
                .then((data) => {
                  item.priceUnit = item.goodsUnit;
                  this.$set(item, "materialList", data);
                  item.materialList.forEach((k) => {
                    if (item.goodsCode == k.goodsCode) {
                      this.$set(
                        item,
                        "goodsSpecificationList",
                        k.goodsSpecificationList
                      );
                      item.goodsType = k.goodsType;
                      item.priceUnit = k.goodsUnit;
                    }
                  });
                });
            });
          }
          this.disabled = this.cartFormData.baseData.isLocked ==0 ?false:true
          if (!this.disabled) {
            this.cartFormData.machineData.push({
              productTechniqueCardMachineID: 0,
              productTechniqueCardMachineCode: "",
              productTechniqueCardCode: "",
              machineCode: "",
              pretreatmentTime: "",
              recommendedSpeed: "",
              coilingTension: "",
              windingTension: "",
              coilTension: "",
            });
            // this.cartFormData.materialData.push({
            //   productTechniqueCardMaterialID: 0,
            //   productTechniqueCardMaterialCode: "",
            //   productTechniqueCardCode: "",
            //   goodsCode: "",
            //   specificationCode: "",
            //   supplierCode: "",
            //   thickness: "",
            // });
            this.cartFormData.inkData.push({
              productTechniqueCardInkID: 0,
              productTechniqueCardInkCode: "",
              productTechniqueCardCode: "",
              colorName: "",
              inkCodeName: "",
              inkRatio: "",
              aniloxRollsQuantity: "",
              meshQuantity: "",
              supplier: "",
            });
          }
          this.pupState = true;
        });
    },

    //供应商选择事件
    supplierChange(row, val) {
      row.stockGoodsCode = "";
      this.$set(row, "materialList", []);
      this.$set(row, "goodsSpecificationList", []);
      row.goodsType = "";
      this.$api.mater
        .GetGoodsSpecificationBySupplierCode({
          queryBy: 0,
          queryValue: val,
        })
        .then((res) => {
          this.$set(row, "materialList", res);
          console.log(row);
          this.$forceUpdate();
        });
    },

    //物料下拉选择事件
    handleMaterialNameChange(row, index, e) {
      if (index == this.cartFormData.materialData.length - 1) {
        this.cartFormData.materialData.push({
          productTechniqueCardMaterialID: 0,
          productTechniqueCardMaterialCode: "",
          productTechniqueCardCode: "",
          goodsCode: "",
          specificationCode: "",
          supplierCode: "",
          thickness: "",
        });
      }
      row.specificationCode = "";
      row.materialList.forEach((item, i) => {
        if (item.goodsCode == e) {
          row.goodsType = item.goodsType;
          this.$set(row, "goodsSpecificationList", item.goodsSpecificationList);
        }
      });
    },

    //资料卡保存
    handleCarSave() {
      this.cartFormData.machineData.pop();
      this.cartFormData.materialData.pop();
      this.cartFormData.inkData.pop();
      this.$api.business
        .UpdateProductTechniqueCard(this.cartFormData)
        .then((res) => {
          this.$message.success("保存成功");
          this.getDetail();
          this.pupState = false;
        });
    },

    //取消
    handleCancel() {
      this.$confirm("信息尚未保存，是否保存?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning",
      })
        .then(() => {
          this.handleSave();
        })
        .catch(() => {
          this.isShowEdits = true;
          this.$emit("showEditEvent", this.isShowEdits);
          this.getDetail(this.productCode);
          this.isDisable = true;
        });
    },

    //编辑
    handleEdit() {
      if (this.isShowEdits) {
        this.isDisable = false;
        this.isShowEdits = false;
        this.$emit("showEditEvent", this.isShowEdits);
        this.formData.productTechniqueList.push({
          productTechniqueID: 0,
          productTechniqueCode: "",
          craftCode: "",
          deviceCode: "",
          craftRequirement: "",
          productCode: this.productCode,
        });
      } else {
        this.$message.warning("有未保存的编辑，请保存后再编辑");
      }
    },

    //保存
    handleSave() {
      this.formData.productTechniqueList.forEach((item, index) => {
        if (!item.craftCode) {
          this.formData.productTechniqueList.splice(index, 1);
        }
      });
      this.$api.business.UpdateProductTechnique(this.formData).then((res) => {
        let obj = {
          state: 4,
          productCode: this.productCode,
        };
        this.$api.business.UpdateProductState(obj).then((res) => {
          this.isShowEdits = true;
          this.$emit("showEditEvent", this.isShowEdits);
          this.$message.success("保存成功");
          this.getDetail(this.productCode);
        });
        this.isDisable = true;
      });
    },

    //获取详情
    getDetail(id) {
      this.$emit("init", "");
      // const parmas = {
      //   queryBy: 2,
      //   queryValue: id,
      // };
      // this.$api.business.GetSingleProductByProductCode(parmas).then((res) => {
      //   this.formData.productTechniqueList = res.productTechniqueList;
      //   if(this.formData.productTechniqueList.length>0){
      //     this.formData.productTechniqueList.forEach((item)=>{
      //       item.produceMachineList.forEach((x)=>{
      //         x.equipmentName = x.machineName
      //         x.equipmentCode = x.machineCode
      //       })
      //     })
      //   }
      // });
    },

    //工艺选择事件
    handleCraftChange(index, e) {
      this.$api.business
        .SureChooseProduceCraftEquipmentMaps({ craftCodes: [e] })
        .then((res) => {
          this.$set(
            this.formData.productTechniqueList[index],
            "produceMachineList",
            res[0].craftEquipments
          );
          // this.formData.productTechniqueList[index].produceMachineList = res[0].craftEquipments
          this.$forceUpdate();
          // this.equipmentList = res[0].craftEquipments;
        });
      if (index == this.formData.productTechniqueList.length - 1) {
        this.formData.productTechniqueList.push({
          productTechniqueID: 0,
          productTechniqueCode: "",
          craftCode: "",
          deviceCode: "",
          craftRequirement: "",
          produceMachineList: [],
          productCode: this.productCode,
        });
      }
      console.log(this.formData.productTechniqueList[index]);
    },

    //获取工艺列表
    getCraftList() {
      this.$api.business
        .GetMatchProductCrafts({ likeWords: "" })
        .then((res) => {
          this.craftList = res;
          if (this.craftList.length > 0) {
            this.craftList.forEach((item) => {
              item.label = item.name;
              item.value = item.deviceCode;
            });
          }
        });
    },
  },
};
</script>

      <style lang="scss" scoped>
.footer {
  display: flex;
  justify-content: center;
}

.title h3:before {
  content: "" !important;
  padding-right: 9px !important;
  border-left: 3px solid #3f61f1;
}
</style>
